﻿#ifndef SERIALPORT_H
#define SERIALPORT_H

#include <QObject>
#include <QList>
#include <QTimer>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>

class SerialPort : public QObject
{
    Q_OBJECT
public:
    explicit SerialPort(QObject *parent = nullptr);
    void scanSerial();
    bool openUart(QString strUartName, int nPort);
    bool closeUart();
    bool isOpen();
public slots:
    int sendData(QByteArray data, int datalen);
private:
    void readData();
signals:
    void RecvData(QByteArray databuf, int datalen);
    void SerialPortList(QList<QSerialPortInfo> serialList, int curIndex);

private:
    QByteArray m_readArray;
    bool m_isOpen;
    QTimer* m_QueryPortTimer;
    QTimer* m_RecvTimer;

    QSerialPort* m_SerialPort;
    QSerialPortInfo* m_PortInfo;

    QList<QSerialPortInfo> m_PortInfolist;
};

#endif // SERIALPORT_H
